﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.Read.Api.Application.Command;
using B.S.BaseData.Read.Api.Dtos;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DepmentController : ControllerBase
    {

        private readonly IMediator mediator;
        private readonly ILogger<DepmentController> logger;

        public DepmentController(IMediator mediator, ILogger<DepmentController> logger = null)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 部门显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<DepmentDto>>> GetDep([FromQuery] GetDepmentCommand request, CancellationToken cancellationToken)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询用户部门角色
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<DepUserDto>>> GetDepUserRole([FromQuery] GetDepUserRoleCommand request, CancellationToken cancellationToken)
        {
            try
            {

                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
